package com.example.qxfw.dataBaseManager.nyzjk.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.ny.Diseasedatalib;
import com.example.qxfw.common.entity.ny.StationInfo;
import com.example.qxfw.dataBaseManager.nyzjk.service.LsbchzlkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/5  星期三   23:27
 * @description : 此类用来 历史病虫害资料库
 ***************************************/
@ApiIgnore
@Slf4j
@Api(tags = "数据库管理-农业专家库-历史病虫害资料库")
@RestController
@CrossOrigin
@RequestMapping("/LsbchzlkController")
public class LsbchzlkController {

    @Autowired
    private LsbchzlkService lsbchzlkService;

    @ApiOperation("查询所有病虫害资料库")
    @GetMapping("getAllDiseaseDataLib")
    public SysResult getAllDiseaseDataLib() {
        List<Diseasedatalib> allDiseaseDataLib = this.lsbchzlkService.getAllDiseaseDataLib();
        return SysResult.success(allDiseaseDataLib);
    }

    @ApiOperation("获取所有站点id和站点名称")
    @GetMapping("getAllStationInfo")
    public SysResult getAllStationInfo() {
        List<StationInfo> allStationInfo = this.lsbchzlkService.getAllStationInfo();
        return SysResult.success(allStationInfo);
    }

    @ApiOperation("查询作物名称")
    @GetMapping("selectDistinctCropName")
    public SysResult selectDistinctCropName() {
        List<Diseasedatalib> diseasedatalibList = this.lsbchzlkService.selectDistinctCropName("cropname", null);
        return SysResult.success(diseasedatalibList);
    }

    @ApiOperation("查询病虫害名称")
    @GetMapping("selectDistinctType")
    public SysResult selectDistinctType(String cropname) {
        List<Diseasedatalib> diseasedatalibList = this.lsbchzlkService.selectDistinctCropName("type", cropname);
        return SysResult.success(diseasedatalibList);
    }

    @ApiOperation("增加病虫害资料库")
    @GetMapping("saveDiseaseDataLib")
    public SysResult saveDiseaseDataLib(@RequestBody Diseasedatalib diseasedatalib) {
        Integer saveDiseaseDataLib = this.lsbchzlkService.saveDiseaseDataLib(diseasedatalib);
        if (saveDiseaseDataLib > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }

    @ApiOperation("修改病虫害资料库")
    @GetMapping("updateDiseaseDataLib")
    public SysResult updateDiseaseDataLib(@RequestBody Diseasedatalib diseasedatalib) {
        Integer updateDiseaseDataLib = this.lsbchzlkService.updateDiseaseDataLib(diseasedatalib);
        if (updateDiseaseDataLib > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }

    @ApiOperation("删除病虫害资料库")
    @GetMapping("deleteDiseaseDataLib")
    public SysResult deleteDiseaseDataLib(@RequestBody Diseasedatalib diseasedatalib){
        Integer deleteDiseaseDataLib = this.lsbchzlkService.deleteDiseaseDataLib(diseasedatalib);
        if (deleteDiseaseDataLib > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }



}
